package com.financing.platform.task;

import java.io.IOException;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.financing.platform.dto.TrustRegexDTO;
import com.financing.platform.service.IProductNoticeService;
import com.financing.platform.service.ITrustRegexService;
import com.financing.platform.util.HtmlUnitFetchUtil;
import com.gargoylesoftware.htmlunit.html.DomNode;
import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlPage;

@Controller
@Component(value="fetchXintuoJob" )
public class FetchXintuoJob {
	// 得到下一页的地址
	static String nextRegex = "(.*?\\s*?\\n*?(»|>>|下一页|后页|下页|后一页)\\s*?\\n*?.*?|.*?\\s*?\\n*?&gt\\;\\s*?\\n*?.*?|.*?>\\s*?\\n*?>\\s*?\\n*?<.*?|.*?Next Page.*?)";
	// 得到上一页的地址
	static String upRegex = ".*?上一页.*?";
	static String rqRgex = ".*?((19|20)?\\d{2}(-|/)\\d{1,2}(-|/)\\d{1,2}).*?";
	static String removeKey="(首页|信息披露|.*?上一页.*?|\\s*?\\[\\d+\\]\\s*?|\\:|\\s*?\\d+\\s*?)";
	//是否全量
	static boolean isAllSite=false;
	
	@Autowired
	ITrustRegexService trustRegexService;
	@Autowired
	IProductNoticeService productNoticeService;
	
	Logger logger = Logger.getLogger(FetchXintuoJob.class);

	
	/***
	 * @Title: fetchBeginJob
	 * @Description: 查询所有需要fetch的产品公告网站 进行 数据采集
	 * @param @throws SQLException
	 * @param @throws IOException
	 * @param @throws InterruptedException 设定文件
	 * @return void 返回类型
	 * 
	 * @throws
	 */
	@RequestMapping(value = "/fetchBeginJob.shtml")
	public void fetchBeginJob(HttpServletRequest request,HttpServletResponse response) throws SQLException, IOException,
			InterruptedException {
		
		String companyId=request.getParameter("companyId")==null?"":request.getParameter("companyId");
		int maxPage=request.getParameter("maxPage")==null?0:Integer.parseInt(request.getParameter("maxPage"));
		
		final List<TrustRegexDTO> queryTrustRegex = trustRegexService
				.queryTrustRegex(companyId);
		for (int i = 0; i < queryTrustRegex.size(); i++) {
			Set<String> old=new HashSet<String>();
			List<String> oldUrls=productNoticeService.queryProdcutNoticeUrlList(queryTrustRegex.get(i).getId());
			for (int j = 0; j < oldUrls.size(); j++) {
				old.add(oldUrls.get(j));
			}
			queryTrustRegex.get(i).setMaxPage(maxPage);
			fetchTrust(queryTrustRegex.get(i),old);
		}
	}
	
	@Scheduled(cron = "0 30 03 * * ?") 
	public void fetchBeginJob() throws SQLException, IOException,
			InterruptedException {
		HtmlPage html = HtmlUnitFetchUtil.getHtml("http://1212.ip138.com/ic.asp");
		String ip = html.asXml();
		if(ip.contains("203.156.233.216")||ip.contains("116.226.248.105")){
			logger.info("测试环境不执行  抓取 信托资管  脚本");
			return ;
		}
		try {
			final List<TrustRegexDTO> queryTrustRegex = trustRegexService
					.queryTrustRegex("");
			for (int i = 0; i < queryTrustRegex.size(); i++) {
				try {
					Set<String> old=new HashSet<String>();
					List<String> oldUrls=productNoticeService.queryProdcutNoticeUrlList(queryTrustRegex.get(i).getId());
					for (int j = 0; j < oldUrls.size(); j++) {
						old.add(oldUrls.get(j));
					}
					queryTrustRegex.get(i).setMaxPage(2);
					fetchTrust(queryTrustRegex.get(i),old);
				} catch (Exception e) {
					logger.error("queryTrustRegex error",e);
					HtmlUnitFetchUtil.destory();
				}
			}
		} catch (Exception e) {
			logger.error("queryTrustRegex error",e);
			HtmlUnitFetchUtil.destory();
		}finally{
			HtmlUnitFetchUtil.destory();
			logger.error("queryTrustRegex end");
		}
	}

	


	/**
	 * @throws IOException 
	 * 
	
	* @Title: getDetailInfoByType
	
	* @Description:列表
	
	* @param @param fetch
	* @param @param currentAchs
	* @param @throws MalformedURLException    设定文件
	
	* @return void    返回类型
	
	* @throws
	 */
	public boolean getDetailInfoByType(TrustRegexDTO fetch,
			List<HtmlElement> currentAchs,Set<String> old) throws IOException {
		boolean isOver=false;
		for (int i = 0; i < currentAchs.size(); i++) {
			try {
				HtmlAnchor detailUrl=(HtmlAnchor)currentAchs.get(i);
				logger.debug(detailUrl.asXml());
				HtmlElement detailElement =null;
				HtmlPage detail=null;
				try {
					detail=(HtmlPage) detailUrl.openLinkInNewWindow();
					detailElement = HtmlUnitFetchUtil.getElementByJs(detail.getDocumentElement(), fetch.getContentRgex()).get(0);
				} catch (Exception e1) {
					try {
						detail=null;
						detail =(HtmlPage) detailUrl.click();
						detailElement = HtmlUnitFetchUtil.getElementByJs(detail.getDocumentElement(), fetch.getContentRgex()).get(0);
					} catch (Exception e) {
						continue;
					}
				}
				if(old.contains(detail.getUrl().toString())){
					logger.debug("该URL已存在..."+ detail.getUrl().toString());
					if(isAllSite){
						continue;
					}else{
					    isOver=true;
						break;
					}
				}
				//成立公告产品名称
				String productName="";
				if(!StringUtils.isBlank(fetch.getTitleRegex())){
					try {
						HtmlElement productNameElement = HtmlUnitFetchUtil.getElementByJs(detail.getDocumentElement(), fetch.getTitleRegex()).get(0);
						productName=productNameElement.asText().replaceAll("[\\t\\n\\r]","");
						logger.debug("detail======="+productName);
					} catch (Exception e) {
					}
				}
				if(StringUtils.isBlank(productName)){
					productName=detailUrl.getTextContent().replaceAll("[\\t\\n\\r]","");					
					logger.debug("list======="+productName);
				}
				//成立公告发布日期
				String ggrq="";
				if(!StringUtils.isBlank(fetch.getRqRegex())){
					try {
						HtmlElement rqElement = HtmlUnitFetchUtil.getElementByJs(detail.getDocumentElement(), fetch.getRqRegex()).get(0);
						ggrq=HtmlUnitFetchUtil.fecth(rqElement.asText(), rqRgex, 1);
						logger.debug("rqElement======="+ggrq);
					} catch (Exception e) {
					}
				}
				if(StringUtils.isBlank(ggrq)){
					try {
						ggrq = getGgrq(detailUrl);
						logger.debug("getGgrq======="+ggrq);
					} catch (Exception e) {
						//日期不在当前url中
						logger.debug("日期不在列表中");
					}
				}
				//产品成立公告详情
				String productDetail=detailElement.asXml();
				Map<String,String> productNotice=new HashMap<String, String>();
				productNotice.put("p_content", productDetail);
				productNotice.put("p_name",productName );
				productNotice.put("p_time", ggrq);
				productNotice.put("company_id", fetch.getId()+"");
				productNotice.put("detail_url", detail.getUrl().toString());
				productNotice.put("create_by", "job");
				productNotice.put("update_by", "job");
				logger.info(ggrq+"==================="+productName+"======"+"======="+detail.getUrl().toString());
				logger.debug(productDetail);
				if(productNoticeService==null)continue;//main函数运行 
				try {
					productNoticeService
							.insertProdcutNotice(productNotice);
				} catch (SQLException e) {
					logger.error("新增公告异常", e);
				}
				old.add(detail.getUrl()
						.toString());
			} catch (Exception e) {
				logger.error("新增公告异常", e);
			}
		}
		return isOver;
	}
	/**
	 * @throws IOException 
	 * 
	
	* @Title: getDetailInfoByType2
	
	* @Description:列表
	
	* @param @param fetch
	* @param @param currentAchs
	* @param @throws MalformedURLException    设定文件
	
	* @return void    返回类型
	
	* @throws
	 */
	public boolean getDetailInfoByType2(TrustRegexDTO fetch,
			List<HtmlElement> currentAchs,Set<String> old) throws IOException {
		boolean isOver=false;
		for (int i = 0; i < currentAchs.size(); i++) {
			try {
				HtmlAnchor detailUrl=(HtmlAnchor)currentAchs.get(i);
				//成立公告发布日期
				String ggrq = getGgrq(detailUrl);
				logger.debug("getGgrq======="+ggrq);
				String filePath="D://testDownTrustPro/"+fetch.getDetailType().split(",")[1]+"/"+ggrq+"/"+UUID.randomUUID().toString().replace("-", "")+"."+fetch.getDetailType().split(",")[1];
//			String remota=HtmlUnitFetchUtil.concatHost(fetch.getInitUrl(),detailUrl.getHrefAttribute());
//			logger.debug(remota);
				String currentUrl=HtmlUnitFetchUtil.downloadByWebClient(filePath,detailUrl,old);
				if(StringUtils.isBlank((currentUrl))){
					logger.debug("该URL已存在..."+ currentUrl);
					if(isAllSite){
						continue;
					}else{
						isOver=true;
						break;
					}
				}
				//成立公告产品名称
				String productName=detailUrl.getTextContent().replaceAll("[\\t\\n\\r]","");					
				logger.debug("list======="+productName);
				//产品成立公告详情
				Map<String,String> productNotice=new HashMap<String, String>();
				productNotice.put("p_content", filePath);
				productNotice.put("p_name",productName );
				productNotice.put("p_time", ggrq);
				productNotice.put("company_id", fetch.getId()+"");
				productNotice.put("detail_url",currentUrl);
				productNotice.put("create_by", "job");
				productNotice.put("update_by", "job");
				logger.info(ggrq+"==================="+productName+"======"+"======="+currentUrl);
				if(productNoticeService==null)continue;//main函数运行 
				try {
					productNoticeService
							.insertProdcutNotice(productNotice);
				} catch (SQLException e) {
					logger.error("新增公告异常", e);
				}
				old.add(currentUrl);
			} catch (Exception e) {
				logger.error("新增公告异常", e);
			}
		}
		return isOver;
	}
	/**
	 * @throws IOException 
	 * 
	
	* @Title: getDetailInfoByType3
	
	* @Description:列表
	
	* @param @param fetch
	* @param @param currentAchs
	* @param @throws MalformedURLException    设定文件
	
	* @return void    返回类型
	
	* @throws
	 */
	public boolean getDetailInfoByType3(TrustRegexDTO fetch,
			List<HtmlElement> currentAchs,Set<String> old) throws IOException {
		boolean isOver=false;
		Set<String> cont=new HashSet<String>();
		for (int i = 0; i < currentAchs.size(); i++) {
			try {
				HtmlAnchor detailUrl=(HtmlAnchor)currentAchs.get(i);
				if(cont.contains(detailUrl.asXml()))continue;
				cont.add(detailUrl.asXml());
				logger.debug(detailUrl.asXml());
				HtmlPage openLinkInNewWindow =null;
				try {
					openLinkInNewWindow=(HtmlPage) detailUrl.openLinkInNewWindow();
				} catch (Exception e1) {
					try {
						openLinkInNewWindow=(HtmlPage) detailUrl.click();
					} catch (Exception e) {
						continue;
					}
				}
				List<HtmlElement> elementByJs = HtmlUnitFetchUtil.getElementByJs(openLinkInNewWindow.getDocumentElement(), "a");
				//成立公告产品名称
				String productName="";
				if(!StringUtils.isBlank(fetch.getTitleRegex())){
					try {
						HtmlElement productNameElement = HtmlUnitFetchUtil.getElementByJs(openLinkInNewWindow.getDocumentElement(), fetch.getTitleRegex()).get(0);
						productName=productNameElement.asText().replaceAll("[\\t\\n\\r]","");
						logger.debug("detail======="+productName);
					} catch (Exception e) {
					}
				}
				if(StringUtils.isBlank(productName)){
					productName=detailUrl.getTextContent().replaceAll("[\\t\\n\\r]","");					
					logger.debug("list======="+productName);
				}
				//成立公告发布日期
				String ggrq="";
				if(!StringUtils.isBlank(fetch.getRqRegex())){
					try {
						HtmlElement rqElement = HtmlUnitFetchUtil.getElementByJs(openLinkInNewWindow.getDocumentElement(), fetch.getRqRegex()).get(0);
						ggrq=HtmlUnitFetchUtil.fecth(rqElement.asText(), rqRgex, 1);
						logger.debug("rqElement======="+ggrq);
					} catch (Exception e) {
					}
				}
				if(StringUtils.isBlank(ggrq)){
					try {
						ggrq = getGgrq(detailUrl);
						logger.debug("getGgrq======="+ggrq);
					} catch (Exception e) {
						//日期不在当前url中
						logger.debug("日期不在列表中");
					}
				}
				for (int j = 0; j < elementByJs.size(); j++) {
					HtmlAnchor htmlElement = (HtmlAnchor) elementByJs.get(j);
					if(cont.contains(htmlElement.asXml()))continue;
					cont.add(htmlElement.asXml());
					if(!htmlElement.asXml().replaceAll("[\\t\\n\\r]", "").matches(fetch.getAttRegex())){
						continue;
					}
					String filePath="D://testDownTrustPro/"+fetch.getDetailType().split(",")[1]+"/"+ggrq+"/"+UUID.randomUUID().toString().replace("-", "")+"."+fetch.getDetailType().split(",")[1];
					String currentUrl=HtmlUnitFetchUtil.downloadByWebClient(filePath, htmlElement,old);
					if(StringUtils.isBlank(currentUrl)){
						logger.debug("该URL已存在..."+currentUrl);
						if(isAllSite){
							continue;
						}else{
							isOver=true;
							break;
						}
					}
					//产品成立公告详情
					Map<String,String> productNotice=new HashMap<String, String>();
					productNotice.put("p_content", filePath);
					productNotice.put("p_name",productName );
					productNotice.put("p_time", ggrq);
					productNotice.put("company_id", fetch.getId()+"");
					productNotice.put("detail_url",currentUrl);
					productNotice.put("create_by", "job");
					productNotice.put("update_by", "job");
					logger.info(filePath+"==="+ggrq+"==================="+productName+"============"+currentUrl);
					if(productNoticeService==null)continue;//main函数运行 
					try {
						productNoticeService
								.insertProdcutNotice(productNotice);
					} catch (SQLException e) {
						logger.error("新增公告异常", e);
					}
					old.add(currentUrl);
				}
			} catch (Exception e) {
				logger.error("新增公告异常", e);
			}
		}
		return isOver;
	}
	/**
	 * @throws IOException 
	 * 
	
	* @Title: getDetailInfoByType4
	
	* @Description:列表
	
	* @param @param fetch
	* @param @param currentAchs
	* @param @throws MalformedURLException    设定文件
	
	* @return void    返回类型
	
	* @throws
	 */
	public boolean getDetailInfoByType4(TrustRegexDTO fetch,
			List<HtmlElement> currentAchs,Set<String> old) throws IOException {
		boolean isOver=false;
		for (int i = 0; i < currentAchs.size(); i++) {
			try {
				HtmlAnchor detailUrl=(HtmlAnchor)currentAchs.get(i);
				HtmlPage openLinkInNewWindow =  (HtmlPage) detailUrl.openLinkInNewWindow();
				List<HtmlElement> elementByJs = HtmlUnitFetchUtil.getElementByJs(openLinkInNewWindow.getDocumentElement(), "a");
				for (int j = elementByJs.size()-1; j >=0; j--) {
					HtmlAnchor an=(HtmlAnchor) elementByJs.get(j);
					if(!an.getHrefAttribute().matches(fetch.getAttRegex())){
						elementByJs.remove(j);
					}
				}
				for (int j = 0; j < elementByJs.size(); j++) {
					HtmlAnchor htmlElement = (HtmlAnchor) elementByJs.get(j);
					logger.debug(htmlElement.asXml());
					HtmlPage detailPage = htmlElement.click();
					if(old.contains(detailPage.getUrl().toString())){
						logger.debug("该URL已存在..."+ detailPage.getUrl().toString());
						if(isAllSite){
							continue;
						}else{
							isOver=true;
							break;
						}
					}
					HtmlElement detail=HtmlUnitFetchUtil.getElementByJs(detailPage.getDocumentElement(), fetch.getContentRgex()).get(0);
					String productDetail=detail.asXml();
					//成立公告产品名称
					String productName="";
					if(!StringUtils.isBlank(fetch.getTitleRegex())){
						try {
							HtmlElement productNameElement = HtmlUnitFetchUtil.getElementByJs(detailPage.getDocumentElement(), fetch.getTitleRegex()).get(0);
							productName=productNameElement.asText().replaceAll("[\\t\\n\\r]","");
							logger.debug("detail======="+productName);
						} catch (Exception e) {
						}
					}
					if(StringUtils.isBlank(productName)){
						productName=detailUrl.getTextContent().replaceAll("[\\t\\n\\r]","");					
						logger.debug("list======="+productName);
					}
					//成立公告发布日期
					String ggrq="";
					if(!StringUtils.isBlank(fetch.getRqRegex())){
						try {
							HtmlElement rqElement = HtmlUnitFetchUtil.getElementByJs(detailPage.getDocumentElement(), fetch.getRqRegex()).get(0);
							ggrq=HtmlUnitFetchUtil.fecth(rqElement.asText(), rqRgex, 1);
							logger.debug("rqElement======="+ggrq);
						} catch (Exception e) {
						}
					}
					if(StringUtils.isBlank(ggrq)){
						try {
							ggrq = getGgrq(detailUrl);
							logger.debug("getGgrq======="+ggrq);
						} catch (Exception e) {
							//日期不在当前url中
							logger.debug("日期不在列表中");
						}
					}
					//产品成立公告详情
					Map<String,String> productNotice=new HashMap<String, String>();
					productNotice.put("p_content", productDetail);
					productNotice.put("p_name",productName );
					productNotice.put("p_time", ggrq);
					productNotice.put("company_id", fetch.getId()+"");
					productNotice.put("detail_url", detailPage.getUrl().toString());
					productNotice.put("create_by", "job");
					productNotice.put("update_by", "job");
					logger.info(ggrq+"==================="+productName+"======"+"======="+detailPage.getUrl().toString());
					if(productNoticeService==null)continue;//main函数运行 
					try {
						productNoticeService
								.insertProdcutNotice(productNotice);
					} catch (SQLException e) {
						logger.error("新增公告异常", e);
					}
					old.add(detailPage.getUrl().toString());
				}
			} catch (Exception e) {
				logger.error("新增公告异常", e);
			}
		}
		return isOver;
	}
	/**
	 * 
	
	* @Title: getGgrq
	
	* @Description: 从列表元素获取公告成立时间   （递归  父元素查找）
	
	* @param @param detailUrl
	* @param @return    设定文件
	
	* @return String    返回类型
	
	* @throws
	 */
	public static String getGgrq(DomNode detailUrl) {
		//从父类元素中获取
		DomNode parentNode = detailUrl;
		String ggrq=HtmlUnitFetchUtil.fecth(parentNode.asXml(),rqRgex, 1);
		if(StringUtils.isBlank(ggrq)&&!parentNode.getNodeName().equals("div")){
			detailUrl=detailUrl.getParentNode();
			return getGgrq(detailUrl);
		}
		return ggrq;
	}

	/**
	 * @throws InterruptedException
	 * @throws IOException
	 * 
	 * @Title: fetchTrust
	 * @Description: 获取信托公告
	 * @param @param initUrl 初始化url
	 * @param @param regexUrl 符合条件的url
	 * @param @param hasHost host
	 * @param @return 设定文件
	 * 
	 * @return String 返回类型
	 * 
	 * @throws
	 */
	
	public String fetchTrust( TrustRegexDTO fetch,Set<String> old) throws IOException,
			InterruptedException {
				String initUrl = fetch.getInitUrl();
				String regexUrl = fetch.getRegexUrl();
				if ("2".equals(fetch.getOpenJs())) {// 传参为2时 ，需要加载页面js
					HtmlUnitFetchUtil.initClient(true);
				}else{
					HtmlUnitFetchUtil.initClient(false);
				}
				try {
					// 下一页标签
					HtmlElement nextPageUrl = null;
					HtmlPage initPage = null;
//					String lastUrl="";
					do {
						//控制最大获取页数
						if(fetch.getMaxPage()>0){
							if(fetch.getMaxPage()>1){//大于1的时候  每抓取一页减1
								fetch.setMaxPage(fetch.getMaxPage()-1);
							}else{//等于1的时候结束
								break;
							}
						}
						try {
							if (nextPageUrl == null) {
								initPage = HtmlUnitFetchUtil.getHtml(initUrl);
							} else {
								initPage= ((HtmlPage) nextPageUrl.click());
//							if(initPage.getUrl().toString().equals(lastUrl)){
//								logger.error("最后一页..........."+lastUrl);
//								break;
//							}
//							lastUrl=initPage.getUrl().toString();
								nextPageUrl = null;
							}
						} catch (Exception e2) {
							break;
						}
						HtmlElement htmlParset=null;
						try {
							htmlParset = initPage.getDocumentElement();
						} catch (Exception e1) {
							break;
						}
						// 有需要截取list内容， 去除非list内容
						if (!StringUtils.isBlank(fetch.getListContentRegex())) {
							htmlParset = HtmlUnitFetchUtil.getElementByJs(
									htmlParset, fetch.getListContentRegex())
									.get(0);
						}
						// 得到当前页所有的A标签
						List<HtmlElement> currentAchs = HtmlUnitFetchUtil
								.getElementByJs(htmlParset, "a");
						Set<String> hasCurrent = new HashSet<String>();
						//下一页
						try {
							if(!StringUtils.isBlank(fetch.getNextRegex())){
								nextPageUrl=HtmlUnitFetchUtil.getElementByJs(htmlParset, fetch.getNextRegex()).get(0);
							}
						} catch (Exception e) {
						}
						for (int i = currentAchs.size() - 1; i >= 0; i--) {
							HtmlAnchor current = (HtmlAnchor) currentAchs
									.get(i);
							// url为空 或者已存在
							if (StringUtils.isBlank(current.getHrefAttribute())
									|| hasCurrent.contains(current
											.getHrefAttribute())) {
								currentAchs.remove(i);
								continue;
							}
							// 是否是下一页url
							if (nextPageUrl==null&&current.asXml().replaceAll("[\\t\\n\\r]","").matches(nextRegex)&&!current.asXml().contains("title=\"最后一页\"")) {
								nextPageUrl = current;
								currentAchs.remove(i);
								continue;
							}
							// 移除不符合条件的url
							if (!current.getHrefAttribute().matches(regexUrl)
									|| current.getTextContent().replaceAll("[\\t\\n\\r]","").matches(
											removeKey)||current.asXml().contains("\"首页\"")) {
								currentAchs.remove(i);
								continue;
							}
							if (!current.getHrefAttribute().equals("#"))
								hasCurrent.add(current.getHrefAttribute());
						}
						if (nextPageUrl != null)
							logger.debug("下一页url:"
									+ nextPageUrl.asXml());
						else
							logger.info("没有搜出下一页。");
						logger.info("剩余:" + currentAchs.size() + "条");
						if(currentAchs.size()==0){
							logger.info("没有搜索出记录!!!");
							break;
						}
						boolean isOver=true;
						//列表页
						if(StringUtils.isNotBlank(fetch.getDetailType())&&"2".equals(fetch.getDetailType().split(",")[0])){
//							isOver=getDetailInfoByType2(fetch, currentAchs,old);
						}else if(StringUtils.isNotBlank(fetch.getDetailType())&&"3".equals(fetch.getDetailType().split(",")[0])){
//							isOver=getDetailInfoByType3(fetch, currentAchs,old);
						}else if(StringUtils.isNotBlank(fetch.getDetailType())&&"4".equals(fetch.getDetailType().split(",")[0])){
							isOver=getDetailInfoByType4(fetch, currentAchs,old);
						}else{
							isOver=getDetailInfoByType(fetch,currentAchs,old);
						}
						//如果增量查询已遇到想同数据
						if(isOver){
							nextPageUrl=null;
						}
					} while (nextPageUrl != null);
				} catch (Exception e) {
					logger.error("fetch error", e);
				}finally{
					HtmlUnitFetchUtil.destory();
				}

		return "OK";
	}
}

